package edu.towson.cis.cosc490.jpanne1.lab3;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;

public class AddItemActivity extends Activity implements OnClickListener{
	
	Button m_addButton;
	EditText m_editText;
	RadioButton m_RadioHigh;
	RadioButton m_RadioMedium;
	RadioButton m_RadioLow;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_item);
		initLayout();
		m_addButton.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_add_item, menu);
		return true;
	}
	
	private void initLayout(){
		m_addButton = (Button) this.findViewById(R.id.addItemButton);
		m_editText = (EditText) this.findViewById(R.id.addItemText);
		m_RadioHigh = (RadioButton) this.findViewById(R.id.radioHigh);
		m_RadioMedium = (RadioButton) this.findViewById(R.id.radioMedium);
		m_RadioLow = (RadioButton) this.findViewById(R.id.radioLow);
	}
	
	@Override
	public void onClick(View v) {
		String stringToDo = m_editText.getText().toString();
		ToDoItem toDoObject = new ToDoItem(stringToDo);
		if(m_RadioHigh.isChecked()){
			toDoObject.setPriority(3);
		} else if(m_RadioMedium.isChecked()){
			toDoObject.setPriority(2);
		} else if(m_RadioLow.isChecked()){
			toDoObject.setPriority(1);
		}
		Intent returnIntent = new Intent();
		returnIntent.putExtra("result", toDoObject.getToDoItemWithPriority());
		setResult(RESULT_OK, returnIntent);
		finish();
	}

}
